package com.qys.livesMall.shop.modal.entity;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.LocalDateTime;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 店铺事件失败重试表
 * </p>
 *
 * @author
 * @since 2023-11-02
 */
@Slf4j
@Data
@Builder
@TableName("h2_shop_event_info")
@Schema(name = "ShopEventInfo", description = "店铺事件失败重试表")
public class ShopEventInfo<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    @Schema(description = "店铺id")
    private Long shopId;

    @Schema(description = "事件类型")
    private String eventType;

    @Schema(description = "事件参数")
    private String params;

    @Schema(description = "0:待执行，1：已执行")
    private Integer status = 0;

    @Schema(description = "重试次数")
    private Integer reCount;

    @Schema(description = "最后一次执行时间")
    private LocalDateTime lastDate;


    private String errorLog;
    @TableField(exist = false)
    private T paramObj;



    public String getParams() {
        if (params==null){
            params=JSONObject.toJSONString(paramObj);
        }
        return params;
    }

    public LocalDateTime getLastDate() {
        if (lastDate==null){
            lastDate=LocalDateTime.now();
        }
        return lastDate;
    }

    public Integer getReCount() {
        if (reCount==null){
            return -1;
        }
        return reCount;
    }
}
